<?php
/**
 */



class db_mblog_cron_content extends db_base {
    
	var $table_name = "mblog_cron_content";
	
	function db_mblog_cron_content()
	{
		parent::db_base();
	}
	
	
	
	
	function get_mblog_list_by_test($p=1,$pcount=20)
	{
		return $this->get_alllist($this->table_name,$p,$pcount,"id desc","");
		
	}
	
	

	
	
	function get_list_by_topic_id($p=1,$pcount=10,$topic_id="",$is_used="",$status="")
	{
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-{$is_used}-{$status}-{$p}-{$pcount}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			
			$where= array();
			
			if(strlen($topic_id) > 0)
			{
				$where[] = "topic_id = '{$topic_id}'";
			}
			
			if(strlen($is_used) > 0)
			{
				$is_used = intval($is_used);
				$where[] = "is_used = {$is_used}";
			}
			if(strlen($status) > 0)
			{
				$status = intval($status);
				$where[] = "status = {$status}";
			}
			
			$where= join(" and ",$where);
			
			$content = $this->get_alllist($this->table_name,$p,$pcount,'create_time desc', $where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		return $content;
	}
	
		

	
	function get_count_by_topic_id($topic_id="",$is_used="",$status="")
	{
		
		$mc = mem_cache::get_instance();
		$key = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-{$is_used}-{$status}";
		$cache = $mc->get($key);
		if ($cache === false)
		{
			
			$where= array();
			
			if(strlen($topic_id) > 0)
			{
				$where[] = "topic_id = '{$topic_id}'";
			}
			
			if(strlen($is_used) > 0)
			{
				$is_used = intval($is_used);
				$where[] = "is_used = {$is_used}";
			}
			if(strlen($status) > 0)
			{
				$status = intval($status);
				$where[] = "status = {$status}";
			}
			
			$where= join(" and ",$where);
			
			$content = $this->get_listcount($this->table_name, $where);
			// 保存MC
			$mc->set($key, serialize($content), 0, CACHE_EXPIRE_MIN_5);
		}
		else
		{
			$content = unserialize($cache);
		}
		
		
		return $content;
	}
	
	
		/**
	 * 用户注册
	 * @param $user_name
	 * @param $password
	 */
	function insert_mblog_cron_content($uid,$user_nickname,$type,$title,$content)
	{
		// 插入数据
		$ary = array();

		$ary["uid"] = $uid;
		$ary["user_nickname"] = $user_nickname;
		$ary["type"] = $type;
		$ary["title"] = $title;
		$ary["content"] = $content;
		

		$ary["create_time"] = Date::get_date_time();
		$ary["create_ip"] = IP::get_client_ip_long();
		$ary["update_time"] = Date::get_date_time();
		$ary["update_ip"] = IP::get_client_ip_long();
		$ary["status"] = 1;
		
		$ret = $this->insert($this->table_name, $ary);
		if ($ret)
		{
			$memcache = mem_cache::get_instance();
			$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-1-1";
			$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-0-1";
			$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}--1";
			$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-1-1-1-20";
			$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-0-1-1-20";
			$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}--1-1-20";
			$memcache->delete_ary($key);
		}
		else
		{
			return false;
		}


		return $this->get_lastinsertid();
	}
	
	function update_mblog_info_by_id($id,$is_used="",$status="")
	{
		$where = "id = $id";
		$ary = array();

		if(strlen($is_used)>0)$ary["is_used"] = $is_used;
		if(strlen($status)>0)$ary["status"] = $status;
		$ret = $this->update($this->table_name, $ary,$where);
		
		
		$memcache = mem_cache::get_instance();
		$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-1-1";
		$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-0-1";
		$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}--1";
		$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-1-1-1-20";
		$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}-0-1-1-20";
		$key[] = CACHE_PREFIX_USER_ITEM."-get_count_by_topic_id-{$topic_id}--1-1-20";
		$memcache->delete_ary($key);
		
		
		
		return $ret;
	}
	
###########################

	
	
	
	/**
	 * cron 获取food_tag
	 */
	function admin_get_count_by_search($status="",$is_used="",$topic="",$min_height="",$max_height="")
	{
		$where= array();
		if(strlen($status) > 0)
		{
			$status = intval($status);
			$where[] = "status = {$status}";
		}
		
		if(strlen($is_used) > 0)
		{
			$is_used = intval($is_used);
			$where[] = "is_used = {$is_used}";
		}
		
		if(strlen($topic) > 0)
		{
			$where[] = "topic = '{$topic}'";
		}
		if($min_height) 
		{
			$where[] = "pic_height_pubu > '{$min_height}'";
		}
		if($max_height)
		{
			$where[] = "pic_height_pubu < '{$max_height}'";
		}
		
		$where[] = "status = 1 ";
		
		$where= join(" and ",$where);
		
		$data = $this->get_listcount($this->table_name, $where);
		
		return $data;
	}
	
	
	/*
	 * cron获取topic_lisy
	 */
	function admin_get_list_by_search($status="",$is_used="",$p=1,$pcount=10,$topic="",$min_height="",$max_height="")
	{
		$where= array();
		if(strlen($status) > 0)
		{
			$status = intval($status);
			$where[] = "status = {$status}";
		}
		if(strlen($is_used) > 0)
		{
			$is_used = intval($is_used);
			$where[] = "is_used = {$is_used}";
		}
		
		if(strlen($topic) > 0)
		{
			$where[] = "topic = '{$topic}'";
		}
		
		if($min_height) 
		{
			$where[] = "pic_height_pubu > '{$min_height}'";
		}
		if($max_height)
		{
			$where[] = "pic_height_pubu < '{$max_height}'";
		}
		
		$where[] = "status = 1 ";
		
		$where= join(" and ",$where);
		
		$p = intval($p);
		$pcount = intval($pcount);
		
		
		$data = $this->get_alllist($this->table_name,$p,$pcount,"create_time desc",$where);
		
		return $data;
	}
	
	function admin_update_mblog_info_by_id($id,$is_used="",$status="")
	{
		$where = "id = $id";
		$ary = array();

		if(strlen($is_used)>0)$ary["is_used"] = $is_used;
		if(strlen($status)>0)$ary["status"] = $status;
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
	}
	##############
	
	function cron_get_data_list_width_wrong($p,$pcount)
	{
		
		$where = "pic_height_pubu = 0 and pic!='' and create_ip != -1";
		$data = $this->get_alllist($this->table_name,$p,$pcount,"",$where);
		return $data;
	}
	
	
	
	function cron_get_data_count_width_wrong()
	{
		
		$where = "pic_height_pubu = 0 and pic!='' and create_ip != -1";
		$data = $this->get_listcount($this->table_name,$where);
		return $data;
	}
	
	function cron_update_mblog_info_by_id($id,$pic_width_pubu="",$pic_height_pubu="",$status="")
	{
		$where = "id = $id";
		$ary = array();

		if(strlen($pic_width_pubu)>0)$ary["pic_width_pubu"] = $pic_width_pubu;
		if(strlen($pic_height_pubu)>0)$ary["pic_height_pubu"] = $pic_height_pubu;
		if(strlen($status)>0)$ary["status"] = $status;
		$ret = $this->update($this->table_name, $ary,$where);
		
		return $ret;
	}
	
}



